package com.itheima.sh.d_gather_03;

import java.util.ArrayList;

public class CarTest {
    public static void main(String[] args) {
        Car car = new Car("雅阁",235800,500);
        Car car1 = new Car("Mkz",268800,520);
        Car car2 = new Car("帕萨特",265800,525);
        Car car3 = new Car("CT5",288800,600);
        ArrayList<Car> cars = new ArrayList<>();
        cars.add(car);
        cars.add(car1);
        cars.add(car2);
        cars.add(car3);
        ArrayList<Car>filter=filter(cars,230000,520);
        for (int i = 0; i < filter.size(); i++) {
            Car car4 = filter.get(i);
            String brand = car4.getBrand();
            int price = car4.getPrice();
            int mile = car4.getMile();
            System.out.println(brand+"--"+price+"--"+mile);
        }
    }


    public static ArrayList<Car> filter(ArrayList<Car> list, int price , int mile){
        ArrayList<Car> newCar = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Car car = list.get(i);
            int price1 = car.getPrice();
            int mile1 = car.getMile();
            String brand = car.getBrand();
            if(price1>price&&mile1>mile){
                newCar.add(car);
            }
        }
        return newCar;
    }
}
